
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="dao.ProductDAO" %>
<%@ page import="dao.CategoriesDAO" %>
<%@ page import="model.ProductModel" %>
<%@ page import="model.CategoriesModel" %>
<%@page import="java.util.ArrayList"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>

        <c:set var="productList" value = '${requestScope.productList}' scope="session"></c:set>

        <title>Search Page</title>
    </head>
    <body>
    <div id="main_container">
        <!-- S HEAD CONTENT -->
        <jsp:include page="block/header.jsp" />
        <!-- E HEAD CONTENT -->

        <!-- S Top Menu -->
        <jsp:include page="block/top_menu.jsp" />
        <!-- E Top Menu -->

        <!-- S Navigation -->
        <jsp:include page="block/navigation.jsp" />
        <!-- E Navigation -->

        <!-- S Left Menu -->
        <jsp:include page="block/left_menu.jsp" />
        <!-- E Left Menu -->

        <!-- S Body Content -->
        <div class="center_content">
            <form action="ProductController?search=yes" id="search" name="search" method="post">
            <table align="center">
                <tr>
                    <td colspan="2" align="center"><h2> Search Product </h2></td>
                </tr>
                <tr>
                    <td>
                        Category : 
                            <select name="cboCategories" id="cboCategories" onchange="" style="width: 200px">
                                <option value=""> --- Select --- </option>
                                <c:forEach var="objCategories" items="<%= CategoriesDAO.getAllCategories() %>">
                                    <option value="${objCategories.id}"  <c:if test="${objCategories.id eq objProDetails.cateID}"> selected </c:if> >${objCategories.cateName}</option>
                                </c:forEach>
                            </select>
                    </td>
                    <td>Product name :
                        <input type="text" id="txtProName" name="txtProName" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="right">
                        <input type="submit" value="Search" name="Search" class="button" />
                    </td>
                </tr>
            </table>
            </form>
            <c:if test="${not empty productList}">
                <div class="productList">
                    <ul>
                    <c:forEach var="objProduct" items="${productList}">
                        <li>
                            <div class="productItemHeader">&nbsp;</div>
                            <div class="productItemImage">
                                <c:choose>
                                    <c:when test="${ not empty objProduct.image }">
                                        <c:forTokens items="${ objProduct.image }" delims="|" var="image" end="0">
                                            <a href="productDetails.jsp?proID=${objProduct.id}&proDetails=yes">
                                                <img alt="${ objProduct.proName }" src="${objProduct.image}" width="125px" border="0" />
                                            </a>
                                        </c:forTokens>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="productDetails.jsp?proID=${objProduct.id}&proDetails=yes">
                                            <img alt="${objProduct.proName}" src="images/noimg.jpg" width="125px" border="0" />
                                        </a>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <div class="productItemPrice">
                                <a href=productDetails.jsp?proID=${objProduct.id}&proDetails=yes">${ objProduct.proName }</a>
                                <br />
                                Price:<span class="productPrice"><fmt:formatNumber value="${objProduct.price}" type="currency" maxFractionDigits="2" /></span>
                            </div>
                            <div class="productItemAction">
                                <input type="button" value="Add to cart" name="btnAddCart" class="cart-button"
                                    <c:if test="${not empty sessionScope.userID}" >
                                       onclick='location.href="ShoppingCardController?action=add&productID=${objProduct.id}"' </c:if>/>
                            </div>
                        </li>
                    </c:forEach>
                    </ul>
                </div>
            </c:if>
        </div>
        <!-- E Body Content -->

        <!-- S Footer -->
        <jsp:include page="block/footer.jsp" />
        <!-- E Footer -->
    </div>
    </body>
</html>
